package com.lzs.adx.web.modules.job.task;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.http.HttpUtil;
import com.lzs.adx.web.modules.adx.dto.AccountDTO;
import com.lzs.adx.web.modules.adx.dto.OcpxAccountDTO;
import com.lzs.adx.web.modules.adx.service.AccountService;
import com.lzs.adx.web.modules.adx.service.OcpxAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class OcpxAccountLimitTask implements ITask{

    @Autowired
    private OcpxAccountService accountService;

    @Override
    public void run(String params) {
        log.info("开始执行日限制预算恢复的功能任务---");
        Map<String,Object> paramsMap=new HashMap<>();
        paramsMap.put("status","3");
        List<OcpxAccountDTO> list = accountService.list(paramsMap);

        if(CollectionUtil.isNotEmpty(list)){
            for (OcpxAccountDTO ocpxAccountDTO : list) {
                ocpxAccountDTO.setStatus("1");
                accountService.update(ocpxAccountDTO);
            }
            //刷新远程的账户缓存
            HttpUtil.get("https://lhpapi.weijingrui.com/common/ocpxdb");
        }

    }
}
